package com.warehouse_management.purchase.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.warehouse_management.config.PageModel;
import com.warehouse_management.purchase.dao.ProductDao;
import com.warehouse_management.purchase.model.*;
import com.warehouse_management.purchase.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @PACKAGE_NAME: com.warehouse_management.purchase.service.impl
 * @NAME: ProductServiceImpl
 * @USER: ZhouYongCheng
 * @DATE: 2022/10/3
 * @TIME: 2:55
 * @Description: 商品管理服务层实现类
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductDao,ProductCondition> implements ProductService {

    @Autowired
    private ProductDao productDao;

    @Override
    public PageModel<ProductCondition> PageProductPosition(ProductCondition product, PageModel<ProductCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<ProductCondition> productList = productDao.queryProductList();
        PageInfo<ProductCondition> pageInfo = new PageInfo<>(productList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());

        return pageModel;
    }


    @Override
    public PageModel<ProductCondition> queryProductListByCondition(ProductCondition product, PageModel<ProductCondition> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum()==0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize()==0?1: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(), pageModel.getPageSize());

        List<ProductCondition> conditionList = productDao.queryProductListByCondition(product);
        PageInfo<ProductCondition> pageInfo = new PageInfo<>(conditionList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageModel.getTotalPage());
        pageModel.setData(pageInfo.getList());
        return pageModel;
    }

    @Override
    public int addProduct(ProductCondition product) {
        return productDao.addProduct(product);
    }

    @Override
    public int updateProduct(ProductCondition product) {
        return productDao.updateProduct(product);
    }

    @Override
    public int updateProductStatus(ProductCondition product) {
        return productDao.updateProductStatus(product);
    }

    @Override
    public List<Type> queryType() {
        return productDao.queryType();
    }

    @Override
    public List<Brand> queryBrand(String id) {
        return productDao.queryBrand(id);
    }
}
